package com.pengbei.enshrine.ui.home;


import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.pengbei.enshrine.R;
import com.pengbei.enshrine.base.BaseFragment;
import com.pengbei.enshrine.common.dialog.callback.CommonCallBack;
import com.pengbei.enshrine.common.utils.DialogUtils;
import com.pengbei.enshrine.common.utils.StatusBarUtils;
import com.pengbei.enshrine.common.utils.ToastUtils;
import com.pengbei.enshrine.ui.account.userdata.UserDataActivity;

public class HomeFragment extends BaseFragment {

    private TextView tv_test;

    @Override
    public void onResume() {
        super.onResume();
        if (!isValid()){
            return;
        }
        StatusBarUtils.StatusBarWhiteBgBlackText(mActivity);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_home, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initview(view);
        refreshData();
    }

    private void initview(View view){
        tv_test = view.findViewById(R.id.tv_test);
        tv_test.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(!isValid()){
                    return;
                }
                DialogUtils.showCommonDialog(
                        mActivity,
                        "测试标题",
                        "测试内容",
                        "确定",
                        "取消",
                        new CommonCallBack() {
                            @Override
                            public void Sure() {
                                UserDataActivity.goToThisActivity(mActivity);
                            }

                            @Override
                            public void Cancal() {
                            }
                        });
            }
        });
    }

    public void refreshData() {

    }

    private AppCompatActivity mActivity;

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        mActivity = (AppCompatActivity) context;
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mActivity = null;  // 清理Activity引用
    }

    private boolean isValid(){
        boolean isValid = true;
        if(null==mActivity||mActivity.isFinishing()||mActivity.isDestroyed()){
            isValid = false;
        }
        return isValid;
    }

}
